package com.zcl.app.adapter;

import java.util.List;

import com.zcl.funnygame.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class GameTypeAdapter extends BaseAdapter{

	private List<String> datas ;
	private Context context;
	private LayoutInflater inflater;
	
	public GameTypeAdapter(Context ctx, List<String> data){
		context = ctx;
		datas = data;
		inflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView != null){
			viewHolder = (ViewHolder) convertView.getTag();
		}else{
			convertView = inflater.inflate(R.layout.game_type_item, null);
			viewHolder = new ViewHolder();
			viewHolder.type_name = (TextView) convertView.findViewById(R.id.game_type_name);
			convertView.setTag(viewHolder);
		}
		viewHolder.type_name.setText(datas.get(position));
		if(position == selectItem){
			convertView.setBackgroundColor(Color.RED);
		}else{
			convertView.setBackgroundColor(Color.TRANSPARENT);
		}
		return convertView;
	}
	
	public void setSelectItem(int position){
		this.selectItem = position;
	}
	
	class ViewHolder{
		private TextView type_name;
	}
	
	private int selectItem = -1;
}
